package cn.bs.busuo.account.dao.persist.repository.impl;

import cn.bs.busuo.account.dao.persist.mapper.SightMapper;
import cn.bs.busuo.account.dao.persist.repository.ISightRepository;
import cn.bs.busuo.account.pojo.entity.Sight;
import cn.bs.busuo.account.pojo.param.SightUpdate;
import cn.bs.busuo.account.pojo.vo.SightListVO;
import cn.bs.busuo.account.pojo.vo.SightVO;
import cn.bs.busuo.common.pojo.vo.PageData;
import cn.bs.busuo.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SightRepositoryImpl implements ISightRepository {
    @Autowired
    private SightMapper sightMapper;

    //    新增景点
    @Override
    public void addSight(Sight sight) {
        sightMapper.insert(sight);
    }

    // 删除景点
    @Override
    public void delectSight(SightUpdate sightUpdate) {
        sightMapper.deleteSight(sightUpdate);
    }

    //根据名字搜索景点
    @Override
    public SightVO getSightByName(String name) {
        SightVO sightById = sightMapper.getSightByName(name);
        return sightById;
    }

    //根据id查询景点
    @Override
    public SightVO selectById(Long id) {
        return sightMapper.selectById(id);
    }

    //查询景点列表
    @Override
    public PageData<SightListVO> selectList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SightListVO> list = sightMapper.selectList();
        System.out.println(list);
        PageInfo<SightListVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);

    }

    //根据季节id查询景点
    @Override
    public List<SightListVO> selcteSeason(Long seasonId) {
        List<SightListVO> sightListVOS = sightMapper.selcteSeason(seasonId);
        return sightListVOS;
    }
}
